package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.CustomerMapper;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.service.CustomerService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    private CustomerMapper customerMapper;
    @Override
    public Map<String, Object> getList(Integer page, Integer rows, String customerName) {
        PageHelper.startPage(page,rows);
        List<Customer> list = customerMapper.getList(customerName);
        PageInfo<Customer> pageInfo = new PageInfo<>(list);
        HashMap<String, Object> map = new HashMap<>();
        map.put("total",pageInfo.getTotal());
        map.put("rows",pageInfo.getList());
        return map;
    }

    @Override
    public void delete(String ids) {
        List<String> list = Arrays.asList(ids.split(","));
        customerMapper.delete(list);
    }

    @Override
    public void update(Customer customer) {
        customerMapper.update(customer);

    }

    @Override
    public void insert(Customer customer) {
        customerMapper.insert(customer);
    }
}
